import React, { Component } from 'react';
import { connect } from 'react-redux';

import { Input, Select, Button } from 'antd';
import action from '../../store/action';
import Management_add from './Management_add';
import Management_table from './Management_table';
import { explan } from '../view_public/Add_public';
import { onkeyDown } from '../../store/function';


class index extends React.Component {
    constructor() {
        super();
        this.state = {
            input_value: ''
        }
    }
    render() {
        const { Search } = Input;
        return <div>
            <div>
                {
                    explan('注意：用户通过管理员创建，管理员能够设置其访问权限')
                }
            </div>
            <div className="search_div">
                用户名:
                <Search placeholder="请输入用户名" className="search_input" onChange={(e) => this.handleChange(e)} onKeyUp={(e)=>onkeyDown(e,this.handel_search)}></Search>
                <Button type="primary" className='search_btn' style={{ background: '#FB6137', borderColor: '#FB6137' }} onClick={this.handel_search}>搜索</Button>

            </div>
            <div>
                <Management_add/>
                <Management_table/>
            </div>
        </div>
    }
    handleChange = (e) => {
  
        this.setState({
            input_value: e.target.value
        })
    }
    handel_search = () => {
        let newName = sessionStorage.getItem('admin_key');
        this.$axios.get(`/manager/api/pageGetUserList/0/9999?lUserCode=${newName}&userName=${this.state.input_value}`).then((res) => {
            const { management_search } = this.props;
           
            
            management_search(res.userList)
        
        }).catch((err) => {
            console.log(err);
        })
    }
}

export default connect(state=>({...state.custom}),action.custom)(index);